{% extends "base_portadmin.html" %}

{% block object-tools %}
	<ul class="object-tools">
		<li>
			<a class="addlink" href="/portadmin/portfolio/add/">Add Portfolio</a>
	    </li>
	</ul>
{% endblock %}

{% block content %}

		<div id="JrcLoader" style="display: none;"><img src="{{ MEDIA_URL }}/images/ajaxloading.gif" alt="Loading..." /></div>

		<table cellspacing="0">

			<thead>
			<tr>
			<th class="action-checkbox-column"></th><th>
			PK
			</th><th>
			Name
			</th><th>
			<select id="StatusId" name="status_id" onchange="JrcLoadPortfolios(gPageNr);">
				<option value="0">Status id</option>
				{# for item in MyConstants.STATUS_CHOICES #}
					<option value="1">approved</option>
					<option value="2">deleted</option>
				{# endfor #}
			</select>
			</th><th>
			CST quantity
			</th><th>
			Actions
			</th>
			</tr>
			</thead>


		<tbody id="ParametersTbody">
		</tbody>
		
	</table>


<script type="text/javascript">

	var gPageNr = 1;
	var gIsOperationLoaded = true;

	function JrcLoadPortfolios(page)
	{
		if( gIsOperationLoaded )
		{
			gPageNr = page;
			gIsOperationLoaded = false;
			jQuery("#JrcLoader").show();
			
			var statusId = jQuery("#StatusId").val();
			jQuery.ajax({
				url: "/portadmin/" + gPageNr + "/getportfolios/"
				, data: "status_id=" + statusId
				, success: function(data){ OnJrcPortfoliosLoaded(data); }
				, error: function(){ OnJrcPortfoliosFailed(); }
			});
		}
	}

	function OnJrcPortfoliosLoaded(data)
	{
		gIsOperationLoaded = true;
		jQuery("#JrcLoader").hide();
		jQuery("#ParametersTbody").html(data);
	}

	function OnJrcPortfoliosFailed()
	{
		gIsOperationLoaded = true;
		jQuery("#JrcLoader").hide();
		jQuery("#ParametersTbody").html("<tr><td colspan='5'>Error loading data!</td></tr>");
	}
	
</script>

{% endblock %}


{% block js_on_load %}

	{{ block.super }}

	// Loading initial parameters
	JrcLoadPortfolios(gPageNr);

{% endblock %}
